#pragma once

#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")

#include <dxgi.h>
#include <d3dcommon.h>
#include <d3d11.h>
#include <d3dx10math.h>

namespace System
{
	class Win32Platform;
}

namespace System
{
class Win32Device
{
public:
	Win32Device(Win32Platform* owner, HINSTANCE instance, int showCommand);

	~Win32Device(void);

	void Initialize();

	void Deinitialize();

	void SetHInstance(HINSTANCE instance);

	

	HINSTANCE GetInstance(){return mInstance;}

	HWND GetWindowHandle(){return mWindowHandle;}

	ID3D11Device* GetDevice();

	ID3D11DeviceContext* GetDeviceContext();

	ID3D11RenderTargetView* GetRTVeiw();

	ID3D11DepthStencilView* GetDSV();

	void SetBackBufferRenderTarget();

	IDXGISwapChain* GetSwapChain();

	bool VsyncEnabled();

	D3DXMATRIX& GetWorldMatrix();

	D3DXMATRIX& GetProjectionMatrix();
	 
	D3DXMATRIX& GetOrthMatrix();

	void TurnZBufferOn();
	
	void TurnZBufferOff();

	void TurnOnAlphaBlending();

	void TurnOffAlphaBlending();

	int GetScreenHeight();

	int GetScreenWidth();

private:
	void InitWindowHandle();

	void InitD3DDevice();

	void SetupGraphicCardInfo();

	void SetupSwapChain();

	void SetupBackBuffer();

	void SetupDepthStencil();

	void SetupRasterizer();

	void SetupAlphaBlend();

private:
	bool mVsyncEnabled;
	
	int mVideoCardMemory;
	char mVideoCardDescription[128];

	ID3D11Device* mDevice;
	ID3D11DeviceContext* mDeviceContext;
	
	IDXGISwapChain* mSwapChain;
	ID3D11RenderTargetView* mRenderTargetView;
	
	ID3D11Texture2D* mDepthStencilBuffer;
	ID3D11DepthStencilState* mDepthStencilState;
	ID3D11DepthStencilState* mDepthDisabledStencilState;

	ID3D11DepthStencilView* mDepthStencilView;
	ID3D11RasterizerState* mRasterState;

	D3DXMATRIX mProjectionMatrix;
	D3DXMATRIX mWorldMatrix;
	D3DXMATRIX mOrthoMatrix;

	ID3D11BlendState* mAlphaEnableBlendingState;
	ID3D11BlendState* mAlphaDisableBlendingState;

	D3D_FEATURE_LEVEL mFeatureLevel;
	HDC mHDC;
	HINSTANCE mInstance;
	HWND mWindowHandle;

	const char*	mWindowTitle;						//!< the title name of the window
	const char*	mWindowClass;						//!< the class name of the window

	int mScreenHeight;								//!< the screen height
	int mScreenWidth;								//!< the screen width
	
	int mScreenNumerator;
	int mScreenDenominator;

	int mShowCommand;								//!<
	bool mDepthBufferEnabled;						//!< is the depth buffer enabaled
	
	Win32Platform* mOwner;
	
	HRESULT result; //need to remove
};
}